﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIT.Web.Controls.Template;
using UIT.Controls;
using System.Xml;
using UIT.Controls.Template;

namespace UIT.Web.Renderers
{
    class ClientTemplateRenderer : ITemplateRenderer<DataTemplate>, ITemplateRenderer
    {
        private System.Xml.XmlWriter writer;
        #region IRenderer<ClientTemplate> Members

        public void Render(DataTemplate template)
        {
            IControl control = template.Template.CreateInstance();
            control.DataContext = new Controls.Template.TemplateSyntaxGenerator();
            if (control != null)
            {
                this.Render(control);
            }
        }

        #endregion

        #region IVisitor<ClientTemplate> Members

        public void Visit(DataTemplate visitable)
        {
            Render(visitable);
        }

        #endregion

        #region IWebRenderer Members

        public void Initialize(RendererManager manager, object userObject)
        {
            Manager = manager;
            this.writer = userObject as XmlWriter;
        }

        #endregion

        public RendererManager Manager { get; set; }

        #region ITemplateRenderer Members

        public void Render(UIT.Controls.Template.ITemplate control)
        {
            Render(control as DataTemplate);
        }

        #endregion

    }
}
